package com.learn.training.multithread.chapter11.demo1;

public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        System.out.println("main thread start  " + Thread.currentThread().getName());
        try (UserContext ctx = new UserContext("Andy")) {
            // 可任意调用UserContext.currentUser()方法
            String currentUser = UserContext.currentUser();
            System.out.println("current user: " + currentUser);
        } // 在此自动调用UserContext.close()方法，清除ThreadLocal中关联的数据
         catch (Exception e) {
            e.printStackTrace();
        }

        String currentUser2 = UserContext.currentUser();
        System.out.println("current user: " + currentUser2);

        System.out.println("main thread end   " + Thread.currentThread().getName());

    }
}
